﻿Imports System
Imports System.Configuration
Imports System.Collections

''' <summary>
''' Custom Rule Definiton Collection
''' </summary>
Public Class CustomRuleDefinitionCollection
    Inherits ConfigurationElementCollection

    Public Sub New()
    End Sub

    Public Overrides ReadOnly Property CollectionType() As ConfigurationElementCollectionType
        Get
            Return ConfigurationElementCollectionType.AddRemoveClearMap
        End Get
    End Property

    Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
        Return New CustomRuleDefinition
    End Function

    Protected Overrides Function GetElementKey(ByVal element As ConfigurationElement) As [Object]
        Return CType(element, CustomRuleDefinition).Name
    End Function

    ''' <summary>
    ''' Gets or sets a property or attribute of this configuration element.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The specified property, attribute, or child element.</returns>
    ''' <exception cref="T:System.Configuration.ConfigurationException">
    ''' <paramref name="prop" /> is null or does not exist within the element.</exception>
    ''' <exception cref="T:System.Configuration.ConfigurationErrorsException">
    ''' <paramref name="prop" /> is read only or locked.</exception>
    Default Public Shadows Property Item(ByVal index As Integer) As RuleSet(Of String)
        Get
            Return CType(BaseGet(index), RuleSet(Of String))
        End Get
        Set(ByVal value As RuleSet(Of String))
            If Not (BaseGet(index) Is Nothing) Then
                BaseRemoveAt(index)
            End If
            BaseAdd(index, value)
        End Set
    End Property

    ''' <summary>
    ''' Gets or sets a property or attribute of this configuration element.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The specified property, attribute, or child element.</returns>
    ''' <exception cref="T:System.Configuration.ConfigurationException">
    ''' <paramref name="prop" /> is null or does not exist within the element.</exception>
    ''' <exception cref="T:System.Configuration.ConfigurationErrorsException">
    ''' <paramref name="prop" /> is read only or locked.</exception>
    Default Public Shadows ReadOnly Property Item(ByVal Name As String) As CustomRuleDefinition
        Get
            Return CType(BaseGet(Name), CustomRuleDefinition)
        End Get
    End Property

End Class